'use strict';

// 数据库模型写数据库对应关系
// 就是表的字段和js直接的对应关系
// 有了这个关系，才能把数据查出来，存到一个对象里
// 或者通过一个对象，把数据存到数据库
module.exports = app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const Announce = app.model.define('announce', {
    announce_id: { type: STRING(32), primaryKey: true },
    region_id: STRING(32),
    title: STRING(100),
    content: TEXT,
    release_time: DATE,
    user_id: INTEGER,
    image: TEXT,
    like: INTEGER,
    collection: INTEGER,
    share: INTEGER,
    status: STRING(3),
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
  );

  Announce.associate = function() {
    // 1对1
    app.model.Announce.hasOne(app.model.User, { foreignKey: 'id', sourceKey: 'user_id' });
  };


  return Announce;
};
